import io from 'socket.io-client'

export const connectSocket = (dispatch, userId) => {
  console.log('登录成功，socket已连接服务器！！')
  if (!io.socket) {
    // 与服务端连接
    io.socket = io('ws://localhost:4000')

    // 监听接收的数据
    io.socket.on('receiveMsg', (data)=>{
      console.log('接收到数据', data)
      // 
    })
  }
}

export const sendMesg = ({from, to, content}) => {
  console.log('发送消息', {from, to, content})
  io.socket.emit('sendMsg', {from, to, content})
}

